package com.rgs.skywalking.demo.controller;

import cn.hutool.core.util.StrUtil;
import com.rgs.skywalking.demo.entity.Result;
import com.rgs.skywalking.demo.entity.vo.OrderVO;
import com.rgs.skywalking.demo.feignClient.ProductServiceFeignClient;
import com.rgs.skywalking.demo.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

/**
 * @program: rgs-study0project
 * @description:
 * @author: Mr.Ren
 * @create: 2024-08-31 23:03
 **/
@RestController
@RequestMapping("/order")
@Slf4j
public class OrderController {

    @Autowired
    private OrderService orderService;
    @Autowired
    private ProductServiceFeignClient productServiceFeignClient;

    @GetMapping("/mall/{productId}")
    public Result mall(@PathVariable("productId") String productId){
        Result result = productServiceFeignClient.queryByProductId(productId);
        log.info("productId is:{}",productId);

        String orderId = StrUtil.uuid();
        OrderVO orderVO = orderService.queryByOrderId(orderId);
        log.info("orderId is:{}",orderId);

        Map<String,Object> returnMap = new HashMap<>();
        returnMap.put("productId",productId);
        returnMap.put("orderId",orderId);
        return Result.success(returnMap);
    }

    @GetMapping("queryByOrderId/{orderId}")
    public Result queryByOrderId(@PathVariable String orderId){
        OrderVO orderVO = orderService.queryByOrderId(orderId);
        return Result.success(orderVO);
    }
}
